
package net.atremmedia.gwt.actionjava.examples.bounds.samples;

import net.atremmedia.gwt.actionjava.examples.bounds.samples.curve.DrawCurve;
import net.atremmedia.gwt.actionjava.examples.frame.AJExampleOverview;
import actionjava.display.Graphics;
import actionjava.geom.Point2D;
import actionjava.geom.curve.QuadCurve2D;

public class DrawQuadCurveBounds extends DrawCurve
{
	public static final String NAME = "Draw quadCurve bounds";
	public static final String DESCRIPTION = "Description";
	public static final String EXAMPLE_SRC = "https://code.google.com/p/gwt-actionjava/source/browse/trunk/aj-examples/aj-examples-bounds/src/main/java/net/atremmedia/gwt/actionjava/examples/bounds/samples/DrawQuadCurveBounds.java";

	private Point2D p1;
	private Point2D p2;
	private Point2D cp1;

	public DrawQuadCurveBounds(AJExampleOverview base)
	{
		super(NAME, DESCRIPTION, EXAMPLE_SRC, base);
	}

	/*
	 * ---------------------------------------------------------------
	 *	Constructor & init
	 * ---------------------------------------------------------------
	 */

	private void initialize()
	{
		// Start point
		p1 = new Point2D(450, 50);

		// Control point
		cp1 = new Point2D(100, 450);

		// End point
		p2 = new Point2D(600, 300);
	}

	/*
	 * ---------------------------------------------------------------
	 *	Abstract Overrides
	 * ---------------------------------------------------------------
	 */

	@Override
	public void run()
	{
		initialize();
		super.run(true);

		addChild(getCurveShape());
	}

	@Override
	public void drawCurve(Graphics graph)
	{
		// Quadratic curve line
		graph.beginStroke(CURVE_LINE_COLOR);
		graph.moveTo(p1.x, p1.y);
		graph.quadraticCurveTo(cp1.x, cp1.y, p2.x, p2.y);
		graph.endStroke();
	}

	@Override
	public void drawDots(Graphics graph)
	{
		// P1 dot
		drawDot(p1.x, p1.y, P1_DOT_COLOR, graph);
		// CP1 dot
		drawDot(cp1.x, cp1.y, CP_DOT_COLOR, graph);
		// P2 dot
		drawDot(p2.x, p2.y, P2_DOT_COLOR, graph);
	}

	@Override
	public void drawControlPointLines(Graphics graph)
	{
		// Line connecting P1 / CP1 / P2
		graph.beginStroke(CP_LINE_COLOR);
		graph.moveTo(p1.x, p1.y);
		graph.lineTo(cp1.x, cp1.y);
		graph.lineTo(p2.x, p2.y);
		graph.endStroke();
	}

	@Override
	public void setBounds()
	{
		// Quadratic curve bounds (Rectangle)
		QuadCurve2D quadCurve = new QuadCurve2D(p1, cp1, p2);
		super.setBounds(quadCurve.getBounds());
	}
}
